package com.clayecloud.common.utils;

import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public  class MessageUtil<T>
{

    public interface UnionSimpleView {}

    //状态码
    @ApiModelProperty(value = "请求结果")
    @JsonView(UnionSimpleView.class)
    private boolean result;

    //错误和成功信息
    @ApiModelProperty(value = "补充信息")
    @JsonView(UnionSimpleView.class)
    private String msg;

    //包含的数据
    @ApiModelProperty(value = "包含数据")
    @JsonView(UnionSimpleView.class)
    private T obj;

    private MessageUtil(boolean result, String msg) {
        this.result = result;
        this.msg = msg;
    }

    public static <T> MessageUtil<T> success(String str)
    {
        return new MessageUtil<T>(true,str==null?"操作成功":str);
    }


    public static <T> MessageUtil<T> fail(String str)
    {
        return new MessageUtil<T>(false,str==null?"操作失败":str);
    }

    //添加包含的数据
    public MessageUtil add(T obj)
    {
        this.setObj(obj);
        return this;
    }

}